﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcContrib.Pagination;
using MvcCarConsume.Domain.Entites;

namespace MvcCarConsume.WebUI
{
    public class AdminViewInOrder
    {
        public int OrderId { get; set; }
        public int CarId { get; set; }
        public int Count { get; set; }
        public DateTime BuildDate { get; set; }
        public DateTime BorrowDate { get; set; }
        public DateTime SendDate { get; set; }
        public string UserName { get; set; }
        public decimal Price { get; set; }
        public int State { get; set; }
    }

    public class VMAdminViewOrder
    {
        private static int pagesize = 13;
        public int currentpage;
        public AdminViewInOrder order { get; set; }
        public IPagination<AdminViewInOrder> Orders { get; set; }
        private List<AdminViewInOrder> internallist = new List<AdminViewInOrder>();
        public void LoadCars(IEnumerable<Order> orders, int page)
        {
            currentpage = page;
            if (orders != null)
            {
                foreach (var order in orders)
                    internallist.Add(new AdminViewInOrder
                    {
                        OrderId = order.OrderId,
                        CarId = order.CarId,
                        Count = order.Count,
                        BuildDate = order.BuildDate,
                        BorrowDate = order.BorrowDate,
                        SendDate = order.SendDate,
                        UserName = order.UserName,
                        Price = order.Price,
                        State = order.State
                    });
                Orders = new LazyPagination<AdminViewInOrder>(internallist.AsQueryable(), /*((currentpage-1)*pagesize >= internallist.Count) ? 1 : */page, pagesize);
            }
        }
    }
}